/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * reportGUI.java
 *
 * Created on Apr 11, 2011, 12:14:52 AM
 */

package project3;

import java.util.*;
import java.text.*;
import java.sql.Timestamp;
import javax.swing.*;


/**
 *
 * @author Kevin
 */
public class reportGUI extends javax.swing.JFrame {

    ReportGenerators reportGenerator;
    int currentSelectedOption;

    /** Creates new form reportGUI */
    public reportGUI() {
        initComponents();
        
        currentSelectedOption = 1;
        reportGenerator = new ReportGenerators();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jTextField2 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        reportArea = new javax.swing.JTextArea();
        generateReportButton = new javax.swing.JButton();
        printReportButton = new javax.swing.JButton();
        deleteReportsButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        reportOptionRadio1 = new javax.swing.JRadioButton();
        reportOptionRadio2 = new javax.swing.JRadioButton();
        reportOptionRadio3 = new javax.swing.JRadioButton();
        clearReportField = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        txtStartDate = new javax.swing.JTextField();
        txtEndDate = new javax.swing.JTextField();

        jTextField2.setText("jTextField2");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Report Generator");

        reportArea.setColumns(20);
        reportArea.setRows(5);
        jScrollPane1.setViewportView(reportArea);

        generateReportButton.setText("Generate Sample");
        generateReportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                generateReportButtonActionPerformed(evt);
            }
        });

        printReportButton.setText("Print Report");
        printReportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printReportButtonActionPerformed(evt);
            }
        });

        deleteReportsButton.setText("Delete Reports");
        deleteReportsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteReportsButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel1.setText("Start(Ex: Jan 1, 2011):");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("End(Ex: Jan 1, 2011):");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setText("View Visualizations Organized by:");

        buttonGroup1.add(reportOptionRadio1);
        reportOptionRadio1.setSelected(true);
        reportOptionRadio1.setText("Country -> City -> Algorithm Name");
        reportOptionRadio1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reportOptionRadio1ActionPerformed(evt);
            }
        });

        buttonGroup1.add(reportOptionRadio2);
        reportOptionRadio2.setText("Algorithm Name -> Country -> City");
        reportOptionRadio2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reportOptionRadio2ActionPerformed(evt);
            }
        });

        buttonGroup1.add(reportOptionRadio3);
        reportOptionRadio3.setText("Country -> City -> Username");
        reportOptionRadio3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reportOptionRadio3ActionPerformed(evt);
            }
        });

        clearReportField.setText("Clear Report Field");
        clearReportField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearReportFieldActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setText("Select the range of dates for the records:");

        txtStartDate.setText("Jan 1, 1960");

        txtEndDate.setText("Dec 1, 2011");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(clearReportField)
                                    .addComponent(reportOptionRadio3)
                                    .addComponent(reportOptionRadio2)
                                    .addComponent(reportOptionRadio1)
                                    .addComponent(jLabel3)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(generateReportButton, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(printReportButton, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(deleteReportsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel4))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtStartDate, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
                        .addGap(46, 46, 46)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtEndDate, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
                        .addGap(22, 22, 22))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(txtStartDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtEndDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 418, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(reportOptionRadio1)
                        .addGap(18, 18, 18)
                        .addComponent(reportOptionRadio2)
                        .addGap(18, 18, 18)
                        .addComponent(reportOptionRadio3)
                        .addGap(18, 18, 18)
                        .addComponent(clearReportField)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addComponent(deleteReportsButton, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addComponent(printReportButton, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addComponent(generateReportButton, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void generateReportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateReportButtonActionPerformed
        try{
            DateFormat converter = new SimpleDateFormat("MMM dd, yyyy");
            Date startDate = (Date)converter.parse(txtStartDate.getText());
            Date endDate = (Date)converter.parse(txtEndDate.getText());
            Timestamp start = new Timestamp(startDate.getTime());
            Timestamp end = new Timestamp(endDate.getTime());
            System.out.println("START DATE VALUE: " + start.toString());
            System.out.println("END DATE VALUE: " + end.toString());
            if(reportOptionRadio1.isSelected()){

                reportGenerator.createOptionOneSampleReport(this.reportArea, start, end);
            }
            else if(reportOptionRadio2.isSelected()){
                reportGenerator.createOptionTwoSampleReport(this.reportArea, start, end);
            }
            else{
                reportGenerator.createOptionThreeSampleReport(this.reportArea, start, end);
            }
        }
        catch(java.text.ParseException ex){
            JOptionPane.showMessageDialog(this,"Please enter in a valid date.","Invalid Date",JOptionPane.ERROR_MESSAGE);

        }
        

    }//GEN-LAST:event_generateReportButtonActionPerformed

    private void clearReportFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearReportFieldActionPerformed
        reportArea.setText("");
    }//GEN-LAST:event_clearReportFieldActionPerformed

    private void printReportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printReportButtonActionPerformed
        try{
            DateFormat converter = new SimpleDateFormat("MMM d, yyyy");
            Date startDate = (Date)converter.parse(txtStartDate.getText());
            Date endDate = (Date)converter.parse(txtEndDate.getText());
            Timestamp start = new Timestamp(startDate.getTime());
            Timestamp end = new Timestamp(endDate.getTime());

            OutputSelection outputSelection = new OutputSelection(currentSelectedOption, start, end);
            outputSelection.setVisible(true);
        }
        catch(java.text.ParseException ex){
            JOptionPane.showMessageDialog(this,"Please enter in a valid date.","Invalid Date",JOptionPane.ERROR_MESSAGE);

        }
        
    }//GEN-LAST:event_printReportButtonActionPerformed

    private void deleteReportsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteReportsButtonActionPerformed
        DeleteRecords deleteRecords = new DeleteRecords();
        deleteRecords.setVisible(true);
    }//GEN-LAST:event_deleteReportsButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        System.exit(0);
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void reportOptionRadio1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reportOptionRadio1ActionPerformed
        currentSelectedOption = 1;
    }//GEN-LAST:event_reportOptionRadio1ActionPerformed

    private void reportOptionRadio2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reportOptionRadio2ActionPerformed
        currentSelectedOption = 2;
    }//GEN-LAST:event_reportOptionRadio2ActionPerformed

    private void reportOptionRadio3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reportOptionRadio3ActionPerformed
        currentSelectedOption = 3;
    }//GEN-LAST:event_reportOptionRadio3ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new reportGUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton clearReportField;
    private javax.swing.JButton deleteReportsButton;
    private javax.swing.JButton generateReportButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JButton printReportButton;
    private javax.swing.JTextArea reportArea;
    private javax.swing.JRadioButton reportOptionRadio1;
    private javax.swing.JRadioButton reportOptionRadio2;
    private javax.swing.JRadioButton reportOptionRadio3;
    private javax.swing.JTextField txtEndDate;
    private javax.swing.JTextField txtStartDate;
    // End of variables declaration//GEN-END:variables

}
